home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / wot-20080519-fx.xpi / chrome / wot.jar / content / idn.js < prev    next >
Text File  |  2007-11-11  |  1KB  |  65 lines

  1. /*
  2.     idn.js
  3.  
  4.     Copyright ┬⌐ 2005, 2006, 2007  Against Intuition, Inc. <info@mywot.com>
  5. */
  6.  
  7. /* Provides a simple wrapper for nsIIDNService */
  8. var wot_idn =
  9. {
  10.     init: function()
  11.     {
  12.         try {
  13.             if (this.handle) {
  14.                 return;
  15.             }
  16.             this.handle =
  17.                 Components.classes["@mozilla.org/network/idn-service;1"].
  18.                     getService(Components.interfaces.nsIIDNService);
  19.  
  20.             window.addEventListener("unload", function(e) {
  21.                     wot_idn.unload();
  22.                 }, false);
  23.         } catch (e) {
  24.             dump("wot_idn.init: failed with " + e + "\n");
  25.         }
  26.     },
  27.  
  28.     unload: function()
  29.     {
  30.         this.handle = null;
  31.     },
  32.  
  33.     isidn: function(str)
  34.     {
  35.         try {
  36.             return this.handle.isACE(str);
  37.         } catch (e) {
  38.             dump("wot_idn.isidn: failed with " + e + "\n");
  39.         }
  40.         return false;
  41.     },
  42.  
  43.     utftoidn: function(utf)
  44.     {
  45.         try {
  46.             return this.handle.convertUTF8toACE(utf);
  47.         } catch (e) {
  48.             dump("wot_idn.utftoidn: failed with " + e + "\n");
  49.         }
  50.         return null;
  51.     },
  52.  
  53.     idntoutf: function(idn)
  54.     {
  55.         try {
  56.             return this.handle.convertACEtoUTF8(idn);
  57.         } catch (e) {
  58.             dump("wot_idn.idntoutf: failed with " + e + "\n");
  59.         }
  60.         return null;
  61.     }
  62. };
  63.  
  64. wot_idn.init();
  65.